#include <iostream>
#include <vector>

//给定一个递增数列，给定一个数字，找出该数列中任意两个和为该数字的数

/*
int main()
{
    std::vector<int> v= {9, 4, 2, 8, 6, 1, 0, 3};
    int target = 7;
    std::sort(v.begin(), v.end());
    for(auto& e : v)
    {
        std::cout << e << std::endl;
    }
    
    int left = 0, right = v.size() - 1;
    while(left < right)
    {
        int sum = v[left] + v[right];
        if(sum < target)
        {
            left++;
        }
        else if(sum == target)
        {
            break;
        }
        else if(sum > target)
        {
            right--;
        }
    }
    std::cout << left << "  " << right << std::endl;
    std::cout << v[left] << "  " << v[right] << std::endl;
    return 0;
}
*/

class downSort
{
    public:
    bool operator()(int x, int y) const
    {
        if(x < y) return false;
        else return true;
    }
};

int main()
{
    std::vector<int> v = {8, 3, 6, 1, 0, 5, 2};
    int target = 3;
    std::sort(v.begin(), v.end());

    int right = v.size() - 1, left = 0;
    while(left < right)
    {
        int sum = v[left] + v[right];
        if(sum < target)
        {
            left++;
        }
        else if(sum == target)
        {
            break;
        }
        else if(sum > target)
        {
            right--;
        }
    }

    std::vector<int>::iterator it = v.begin();
    while(it != v.end())
    {
        std::cout << *it << " ";
        it++;
    }
    std::cout << std::endl;
    std::cout << left << " " << right << std::endl;
    return 0;
}